import { defineStore } from 'pinia'
import { toRaw } from 'vue'
import { fnAddDynamicMenuRoutes,existRouteComponent } from '@/utils/dynamicRoutes'
export const useAppStore = defineStore('App', {
  state:() => {
    return {
      layout:'left',
      watermarkEnabled:true,
      watermarkContent:'啊阿文',
      sidebarFold: false,
      refresh:false,
      sidebarMenuActiveId:'',
      navbarMenuActiveId:'',
      token:"",
      sidebarMenuList:[]
    }
  },
  getters: {},
  actions: {
    toggleSidebarFold() {
      this.sidebarFold = !this.sidebarFold
    },
    toggleRefresh(){
      this.refresh = !this.refresh
    },
    toggleLayout(val){
      this.layout = val
    },
    updateSidebarMenuActiveId(val){
      this.sidebarMenuActiveId = val +''
    },
    updateNavbarMenuActiveId(val){
      this.navbarMenuActiveId = val +''
    },
    handleLogin(){
      this.token = '1212'
      this.sidebarMenuList = [
        {
          createdTime: '2020-05-07 23:45:43',
          updatedTime: '2020-05-28 23:10:38',
          deleted: 0,
          id: 9,
          tenantId: null,
          menuName: '系统管理',
          menuEnName: '',
          menuPid: 1,
          menuOrder: 5,
          menuIcon: 'Setting',
          menuFlag: null,
          isVisible: 1,
          menuStatus: 1,
          title: '系统管理',
          routerName: 'sysMgmt',
          routerPath: 'sysMgmt',
          descriptions: 'abstract',
          modelId: null,
          isLeaf: 0,
          childMenus: [
            {
              createdTime: '2020-05-07 23:56:06',
              updatedTime: '2020-10-21 06:30:41',
              deleted: 0,
              id: 5,
              tenantId: null,
              menuName: '用户管理',
              menuEnName: '',
              menuPid: 9,
              menuOrder: 2,
              menuIcon: 'User',
              menuFlag: null,
              isVisible: 1,
              menuStatus: 1,
              title: '用户管理',
              routerName: 'user',
              routerPath: 'sysMgmt/user',
              descriptions: '',
              modelId: null,
              isLeaf: 0,
              childMenus: []
            },
            {
              createdTime: '2020-05-07 23:57:47',
              updatedTime: '2020-05-09 03:58:18',
              deleted: 0,
              id: 6,
              tenantId: null,
              menuName: '角色管理',
              menuEnName: '',
              menuPid: 9,
              menuOrder: 2,
              menuIcon: 'CreditCard',
              menuFlag: null,
              isVisible: 1,
              menuStatus: 1,
              title: '角色管理',
              routerName: 'role',
              routerPath: 'sysMgmt/role',
              descriptions: '',
              modelId: null,
              isLeaf: 0,
              childMenus: []
            }
          ]
        },
        {
          createdTime: '2020-05-01 04:36:52',
          updatedTime: '2020-05-20 06:26:38',
          deleted: 0,
          id: 2,
          tenantId: null,
          menuName: '首页',
          menuEnName: '',
          menuPid: 1,
          menuOrder: 1,
          menuIcon: 'House',
          menuFlag: null,
          isVisible: 1,
          menuStatus: 1,
          title: '首页',
          routerName: 'home',
          routerPath: 'home',
          descriptions: '',
          modelId: null,
          isLeaf: 0,
          childMenus: []
        },
        
      ]
        existRouteComponent(toRaw(this.sidebarMenuList))
        fnAddDynamicMenuRoutes(toRaw(this.sidebarMenuList))
        return Promise.resolve(this.token)
    },
  }
})

